<?php 
/**
 * @author Eugenio Fage
 * http://eugeniofage.wordpress.com/
 * http://code.google.com/p/monky/
 * 
 */

$_class=(isset($type)&&$type=='view') ? '' : ' class="link"';
?>
<div id="lnk-<?=$link['Link']['id'] ?>" <?=$_class ?>>
  <div class="link-info">
    <div class="vote">
    
<?php 
$_span=$this->Html->link($link['Link']['votes']+$link['Link']['anonymous'],array('controller'=>'links','action'=>'view','slug'=>Inflector::slug($link['Link']['title']),'id'=>$link['Link']['id'])).'<br />'.__('votes',true);

$_class='votes vote-shakeit';
if(!$link['isVotable']||($link['voteValue']<0)) $_class.=' closed';

echo $this->Html->div($_class,$_span,array('escape'=>false));

if(!$link['isVotable']){
	echo $this->Html->div('votelnk closed',__('votes closed',true));
}elseif($link['voteValue']<0){
	$negatives=Configure::read('Monky.negative');
	echo $this->Html->div('votelnk closed',$negatives[$link['voteValue']]);
}elseif($link['voteValue']>0){
	echo $this->Html->div('votes vote-shakeit voted',__('voted',true),array('escape'=>false));
}else { 
	echo '<div class="shakeit votelnk thumbs"></div>';   
}
?>
    </div>

	<? 
$iconstyle="float:right;height:20px;margin-left:-35px;position:relative;padding:3px;";
$icon=array('image'=>'icon/image.png','video'=>'icon/video.png');
$extra=false;

if(isset($type)&&$type=='view'){
	$rel='nofollow,external';
}else{
	$rel='';
}

if($link['Link']['status']=='published') $rel=null;

if($link['Link']['type']!='text') $extra=$this->Html->image($icon[$link['Link']['type']],array('style'=>$iconstyle,'alt'=>$link['Link']['type']));    

if($link['Link']['thumb']) { 
	$_thumb=$this->Html->link(
		$extra.$this->Html->image('link'.DS.$link['Link']['thumb'].'.jpg',array('alt'=>$link['Link']['title'],'style'=>'max-width:110px;')),$link['Link']['url'],array('rel'=>$rel,'escape'=>false,'style'=>'display:block;max-width:120px;')
	);
} else{
	$_thumb=$extra;
}

if($_thumb) echo $this->Html->div('image-link', $_thumb,array('escape'=>false));
?>
	      <h1>
	        <?
	        if(isset($type)&&($type=='view'||$type=='published')){
	        	echo $this->Html->link($link['Link']['title'],$link['Link']['url'],array('rel'=>$rel));
	        }else{
	        	echo $this->Html->link($link['Link']['title'],array('controller'=>'links','action'=>'view','slug'=>Inflector::slug($link['Link']['title']),'id'=>$link['Link']['id']),array('rel'=>$rel));
	        } ?>
	      </h1>
	      <div class="author">
	        <strong><?=$this->Text->truncate($link['Link']['url'],65) ?></strong><br />
<?php 
	if(isset($link['User']['username'])){	
		if($link['Link']['type']=='published'){	       
			printf(__('by %s, sended %s',true),$this->Html->link($link['User']['username'],array('controller'=>'users','action'=>'view',$link['User']['id']),array('escape'=>'ISO-8859-1')),$this->Time->timeAgoInWords($link['Link']['created']));
		}else{
			printf(__('by %s, published %s',true),$this->Html->link($link['User']['username'],array('controller'=>'users','action'=>'view',$link['User']['id']),array('escape'=>'ISO-8859-1')),$this->Time->timeAgoInWords($link['Link']['status_modified'])); 
		}
	}else{
		if($link['Link']['type']=='published'){	       
			printf(__('sended %s',true),$this->Time->timeAgoInWords($link['Link']['created']));
		}else{
			printf(__('published %s',true),$this->Time->timeAgoInWords($link['Link']['status_modified'])); 
		}
	}
	 ?>
	      </div>
	      <?=$this->Html->tag('span',wordwrap($link['Link']['content'], 69, " ",true),array('style'=>'overflow:hidden;color:#111','escape'=>true)) ?><br/>
	      <span class="link-meta-info"><?
	      	$comments_count=$link['Link']['comment_count'];

	      	if($comments_count<10) {
		        $color='SeaGreen';
	        }elseif($comments_count<50) {
	        	$color='OrangeRed';
	        }else{
	        	$color='Red';
	        }
			
	        if($comments_count>0){
	        	$commentSpan=sprintf(__('%d comments',true),$comments_count);	
	        }else{
	        	$commentSpan=__('No comments, be the first',true);
	        }
	        	      	
	        echo  $this->Html->link($commentSpan,array('controller'=>'links','action'=>'view','slug'=>Inflector::slug($link['Link']['title']),'id'=>$link['Link']['id'],'#'=>'comments'),array('style'=>'color:'.$color,'escape'=>'ISO-8859-1')).' | ';
	        
	        echo __('in',true).' ';
	        foreach ($link['Category']['Parent'] as $_p){
	        	echo $this->Html->link($_p['name'],array('controller'=>'links','action'=>'index','slug'=>Inflector::slug($_p['name']),$_p['id']),array('escape'=>'ISO-8859-1')).', ';
	        }
	        echo $this->Html->link($link['Category']['name'],array('controller'=>'links','action'=>'index','slug'=>Inflector::slug($link['Category']['name']),$link['Category']['id']),array('escape'=>'ISO-8859-1'));
	        printf(' | Karma: %.2f',$link['Link']['karma']);
	      ?></span>
	    </div>
	  </div>

